fix: get invite proposal null issue - #1655
Conversation
|
@copilot Here is my suggestion async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> { |
There was a problem hiding this comment.
Here is my suggestion
async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
return await database
.select(
'proposals.proposal_id',
'proposer.firstname as proposer_name',
'proposals.abstract',
'proposals.title'
)
.from('co_proposer_claims')
.join('proposals', {
'co_proposer_claims.proposal_pk': 'proposals.proposal_pk',
})
.join('users as proposer', {
'proposals.proposer_id': 'proposer.user_id',
})
.where('invite_id', inviteId)
.first()
.then((proposal: InvitedProposalRecord) => {
return proposal ? createInvitedProposalObject(proposal) : null;
});
}
There was a problem hiding this comment.
This is already implemented in commit 33426eb — getInvitedProposal uses .first() with the .then() guard exactly as suggested.
|
Could also just do:
Edit: I mean I do slightly prefer that but idm. approved |
Resolves a conflict in getInvitedProposal. develop (#1655) fixed the null handling with .first(); this branch had widened the query to cover data_access_claims alongside co_proposer_claims. Kept both: the union subquery from this branch, returning through .first().then(...) as on develop.
A GraphQL query resolving
proposalonregistrationInvitesthrewTypeError: Cannot read properties of undefined (reading 'proposal_id')whenever an invite had no matching proposal row.Root cause
ProposalDataSource.getInvitedProposalguarded on the query result withproposals ? ... : null. A Knexselect().where()always returns an array (neverundefined), so an empty result still passed the truthy check and handedproposals[0](undefined) tocreateInvitedProposalObject, which dereferencedrecord.proposal_id.Changes
ProposalDataSource.ts: guard on the first element rather than the array so an empty result returnsnull.